<?php

namespace Service;

use Core\Di;
/**
 * 错误信息服务类
 * Class MessageService
 * @package Service
 */
class MessageService
{


    /**
     * 获取错误信息
     * @param $code
     * @param string $fieldName
     * @return mixed
     */
    public static function get($code, $fieldName = '')
    {
        $messageList = Di::get('message');
        if( is_numeric($code) AND isset( $messageList[$code] ) ){
            $message = $messageList[$code];
            $message['msg'] = str_replace('{field}', $fieldName, $message['msg']);
            $message['message'] = str_replace('{field}', $fieldName, $message['message']);
            return $message;
        }
    }
}